/*
 * 
 */

import model.Course;
import model.Room;

import stats.PieChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.DefaultXYDataset;

import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;

import etm.core.configuration.EtmManager;
import etm.core.monitor.EtmMonitor;
import etm.core.monitor.EtmPoint;
import etm.core.configuration.BasicEtmConfigurator;
import etm.core.renderer.SimpleTextRenderer;


import java.io.StringWriter;

/**
 *
 * @author Administrator
 * Dinh Ngoc 10.08.2010
 *
 */
public class Main {

    /**
     * @param args the command line arguments
     */

   
    public static void main1(String[] args) {
        InputReader myInputReader = null;

        if (args[0] != null)
        {
            myInputReader = new InputReader(args[0],true);

        }
        else myInputReader = new InputReader("input/comp01.ctt");

        myInputReader.showHardCurMatrixinChart();
        myInputReader.showUnavailabilityMatrixinChart();

        // 1. FirstSolFinder
        FirstSolFinder myFirstSolFinder = new FirstSolFinder();

        myFirstSolFinder.setInputReader(myInputReader);
        myFirstSolFinder.start();

        myFirstSolFinder.showSolutioninChart();

        // 2. RegionDigger
        RegionDigger myRegionDigger = new RegionDigger(myFirstSolFinder);
        //myRegionDigger.Opt1ProbMargin=0.9999999999;
        myRegionDigger.run();
        myRegionDigger.writeSolDown();
        myRegionDigger.showBestSolinChart();
        myRegionDigger.showConvergenceinChart();




       

        // 3. NewRegionExplorer
        NewRegionExplorer myNewRegionExplorer = new NewRegionExplorer(myFirstSolFinder);
        myNewRegionExplorer.attachToRegionDigger(myRegionDigger);
        myNewRegionExplorer.run();
        myNewRegionExplorer.writeSolDown();
        myNewRegionExplorer.showBestSolinChart();
        myNewRegionExplorer.showConvergenceinChart();


    }
    

    
    public static void main(String[] args) {
        // TODO code application logic here
        //InputReader myInputReader = new InputReader("C://comp12.ctt");

        for (int f=1;f<=8;f++)
        {
        // InputReader myInputReader = new InputReader("input/comp01.ctt");
        // initialize measurement subsystem
       
        
        InputReader myInputReader = new InputReader("input/comp0"+f+".ctt");


        System.out.println("input/comp"+"0"+f+".ctt");
        System.out.println("Number of courses: "+myInputReader.CNum);

        System.out.println("#Courses :"+myInputReader.Courses.size());
        System.out.println("#Rooms :"+myInputReader.Rooms.size());

        /*
        System.out.println("HardCurriculum_Matrix");
        for (int i=0;i< myInputReader.HardCurriculum_Matrix.length;i++)
        {
            System.out.print(myInputReader.Courses.get(i).getCourseID()+": ");
            
            for (int j=0;j< myInputReader.HardCurriculum_Matrix[i].length;j++)
            {
                System.out.print(myInputReader.HardCurriculum_Matrix[i][j]+" ");
            }

            System.out.println(" ");
            
        }

        System.out.println();

        System.out.println("SoftCurriculum_Matrix");
        for (int i=0;i< myInputReader.SoftCurriculum_Matrix.length;i++)
        {
            System.out.print(myInputReader.Courses.get(i).getCourseID()+": ");

            for (int j=0;j< myInputReader.SoftCurriculum_Matrix[i].length;j++)
            {
                System.out.print(myInputReader.SoftCurriculum_Matrix[i][j]+" ");
            }

            System.out.println(" ");

        }

        

        String testID = myInputReader.Courses.get(2).getCourseID();
        System.out.println("Index of "+testID+" is "+Course.getPosofID(myInputReader.Courses,testID));
        System.out.println();

        System.out.println("C_P_UnavailabilityMatrix");
        for (int i=0;i< myInputReader.C_P_UnavailabilityMatrix.length;i++)
        {
            System.out.print(myInputReader.Courses.get(i).getCourseID()+": "+" index: "+myInputReader.Courses.get(i).index+"  ");
            
            for (int j=0;j< myInputReader.C_P_UnavailabilityMatrix[i].length;j++)
            {
                System.out.print(myInputReader.C_P_UnavailabilityMatrix[i][j]+" ");
            }

            System.out.println(" ");
            
        }

        myInputReader.calcC_R_Capacity_Constraint();
        System.out.println("C_R_Capacity_Assignment");
        
        for (int i=0;i< myInputReader.C_R_Capacity_Assignment.length;i++)
        {
            System.out.print(myInputReader.Courses.get(i).getCourseID()+": ");

            for (int j=0;j< myInputReader.C_R_Capacity_Assignment[i].length;j++)
            {
                System.out.print(myInputReader.C_R_Capacity_Assignment[i][j]+" ");
            }

            System.out.println(" ");

        }


        myInputReader.calcCourses_waTeacher_Matrix();
        System.out.println("Courses_waTeacher_Matrix");

        for (int i=0;i< myInputReader.Courses_waTeacher_Matrix.length;i++)
        {
            System.out.print(myInputReader.Courses.get(i).getCourseID()+": ");

            for (int j=0;j< myInputReader.Courses_waTeacher_Matrix[i].length;j++)
            {
                System.out.print(myInputReader.Courses_waTeacher_Matrix[i][j]+" ");
            }

            System.out.println(" ");

        }
         * 
         */

       
        myInputReader.showHardCurMatrixinChart();
        myInputReader.showUnavailabilityMatrixinChart();
       
        /*
        
        Course.showCourses(myInputReader.Courses);
        System.out.println("Test Course Sort");
        Course.showCourses(Course.sortByStuNum(myInputReader.Courses));

        System.out.println("Test Room Sort");
        Room.show(Room.sortByCapacity(myInputReader.Rooms));

        System.out.println("########################################");
        System.out.println("Test Solver.passLectureNumandMinWDays( )");
        int [] sol = {1,0,0,0,1,0};
        System.out.println(Solver.passLectureNumandMinWDays(sol, 2, 2, 2));
         * 
         */

        // Test FirstSolFinder
        FirstSolFinder myFirstSolFinder = new FirstSolFinder();

        myFirstSolFinder.setInputReader(myInputReader);
        myFirstSolFinder.start();
        
        myFirstSolFinder.showSolutioninChart();

        //myFirstSolFinder.showBestSolinChart();

        //myFirstSolFinder.HillClimbIterate(2);

        
        //myFirstSolFinder.initSolutionMatrix();
        //myFirstSolFinder.generateFSol4Course(0);
        //myFirstSolFinder.printSolMatrix();

        //RegionDigger myRegionDigger = new RegionDigger(myFirstSolFinder);

        //myRegionDigger.run();
        
        for (int i=0;i< myFirstSolFinder.CP_R_Solution.length;i++)
        {
            System.out.print(myInputReader.Courses.get(i).getCourseID()+": ");

            for (int j=0;j< myFirstSolFinder.CP_R_Solution[i].length;j++)
            {
                System.out.print(myFirstSolFinder.CP_R_Solution[i][j]+" ");
            }

            System.out.println(" ");

        }


      

       
        RegionDigger myRegionDigger = new RegionDigger(myFirstSolFinder);
        //myRegionDigger.Opt1ProbMargin=0.9999999999;
        myRegionDigger.run();
        myRegionDigger.writeSolDown();
        myRegionDigger.showBestSolinChart();
        myRegionDigger.showConvergenceinChart();
        


        /*
        RegionDigger myRegionDigger2 = new RegionDigger(myFirstSolFinder);
        myRegionDigger2.attachToRegionDigger(myRegionDigger);
        // myRegionDigger2.Opt1ProbMargin=0.9999999999;
        myRegionDigger2.run();
        myRegionDigger2.writeSolDown();
        myRegionDigger2.showBestSolinChart();
        */

        
        NewRegionExplorer myNewRegionExplorer = new NewRegionExplorer(myFirstSolFinder);
        myNewRegionExplorer.attachToRegionDigger(myRegionDigger);
        myNewRegionExplorer.run();
        myNewRegionExplorer.writeSolDown();
        myNewRegionExplorer.showBestSolinChart();
        myNewRegionExplorer.showConvergenceinChart();
        

        


        /*
        PernaltyCounter _myPenaltyCounter = new PernaltyCounter();

        myFirstSolFinder.attachTo(_myPenaltyCounter);

        
        System.out.println("_myPenaltyCounter.AllLecturesOnTT() "+_myPenaltyCounter.AllLecturesOnTT());
        System.out.println("_myPenaltyCounter.sameCurriculumLecturesConflict() "+_myPenaltyCounter.sameCurriculumLecturesConflict(myInputReader.HardCurriculum_Matrix, myFirstSolFinder.Cs_sortedCs_Mapping));
        System.out.println("_myPenaltyCounter.sameTeacherLecturesConflict() "+_myPenaltyCounter.sameTeacherLecturesConflict(myInputReader.Courses_waTeacher_Matrix, myFirstSolFinder.Cs_sortedCs_Mapping));
        System.out.println("_myPenaltyCounter.TeacherAvailabilities() "+_myPenaltyCounter.TeacherAvailabilities(myInputReader.C_P_UnavailabilityMatrix, myFirstSolFinder.Cs_sortedCs_Mapping));


        System.out.println("_myPenaltyCounter.RoomOccupancy() "+_myPenaltyCounter.RoomOccupancy());
        System.out.println("_myPenaltyCounter.RoomCapacity() "+_myPenaltyCounter.RoomCapacity());
        System.out.println("_myPenaltyCounter.MinimumWorkingDays() "+_myPenaltyCounter.MinimumWorkingDays(myInputReader.Periods_per_day));
        System.out.println("_myPenaltyCounter.CurriculumCompactness() "+_myPenaltyCounter.CurriculumCompactness());
        System.out.println("_myPenaltyCounter.RoomStability() "+_myPenaltyCounter.RoomStability());
        */



        }

        /*
        for (int f=3;f<=3;f++)
        {



        InputReader myInputReader = new InputReader("input/comp0"+f+".ctt");


        System.out.println("input/comp"+"0"+f+".ctt");
        System.out.println("Number of courses: "+myInputReader.CNum);

        System.out.println("#Courses :"+myInputReader.Courses.size());
        System.out.println("#Rooms :"+myInputReader.Rooms.size());

        myInputReader.showHardCurMatrixinChart();
        myInputReader.showUnavailabilityMatrixinChart();

        FirstSolFinder myFirstSolFinder = new FirstSolFinder();

        myFirstSolFinder.setInputReader(myInputReader);
        myFirstSolFinder.start();

        myFirstSolFinder.showSolutioninChart();



        RegionDigger myRegionDigger = new RegionDigger(myFirstSolFinder);
        myRegionDigger.run();
        myRegionDigger.writeSolDown();
        myRegionDigger.showBestSolinChart();



        NewRegionExplorer myNewRegionExplorer = new NewRegionExplorer(myFirstSolFinder);
        myNewRegionExplorer.attachToRegionDigger(myRegionDigger);
        myNewRegionExplorer.run();
        myNewRegionExplorer.writeSolDown();
        myNewRegionExplorer.showBestSolinChart();

        }


        for (int f=1;f<=1;f++)
        {



        InputReader myInputReader = new InputReader("input/comp1"+f+".ctt");


        System.out.println("input/comp"+"1"+f+".ctt");
        System.out.println("Number of courses: "+myInputReader.CNum);

        System.out.println("#Courses :"+myInputReader.Courses.size());
        System.out.println("#Rooms :"+myInputReader.Rooms.size());

        myInputReader.showHardCurMatrixinChart();
        myInputReader.showUnavailabilityMatrixinChart();
        
        FirstSolFinder myFirstSolFinder = new FirstSolFinder();

        myFirstSolFinder.setInputReader(myInputReader);
        myFirstSolFinder.start();

        myFirstSolFinder.showSolutioninChart();


        

        RegionDigger myRegionDigger = new RegionDigger(myFirstSolFinder);
        myRegionDigger.run();
        myRegionDigger.writeSolDown();
        myRegionDigger.showBestSolinChart();



        NewRegionExplorer myNewRegionExplorer = new NewRegionExplorer(myFirstSolFinder);
        myNewRegionExplorer.attachToRegionDigger(myRegionDigger);
        myNewRegionExplorer.run();
        myNewRegionExplorer.writeSolDown();
        myNewRegionExplorer.showBestSolinChart();
        

        }
        
        */
        

    }



    

}
